package J11_2;


import java.util.*;

//Problem Statement
//There is a grid with
//N rows and
//N columns. The cell at the
//i-th row from the top and
//j-th column from the left is painted black if
//S
//i,j
//  is #, and white if it is ..
//How many distinct patterns of painted cells can be obtained by extracting a region of
//M rows and
//M columns from this grid?
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        long startTime = System.currentTimeMillis();
        char[][] chars = new char[n][n];
        in.nextLine();
        for (int i = 0; i < n; i++) {
            chars[i] = in.nextLine().toCharArray();
        }

        Set<Queue<Character>> set = new HashSet<>();

        for (int i = 0; i < n - m + 1; i++) {
            Queue<Character> queue = new LinkedList<>();
            for (int j = 0; j < m; j++) {
                for (int k = i; k <  i + m; k++) {
                    queue.add(chars[k][j]);
                }
            }
            set.add(new LinkedList<>(queue));
            for (int j = m; j < n; j++) {
                for (int k = 0; k < m; k++) {
                    queue.poll();
                    queue.add(chars[i + k][j]);
                }
                set.add(new LinkedList<>(queue));
            }
        }
        long endTime = System.currentTimeMillis();
        long executionTime = endTime - startTime;
        System.out.println("执行时间: " + executionTime + " 毫秒");
        System.out.println(set.size());

    }
}
